/**
 * @file quick_function.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_WATCH_QUICK_FUNCTION != 0

#include <stdio.h>

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/


/**********************
 *  STATIC PROTOTYPES
 **********************/
static void * get_shutdown_src(void);

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
***********************/
lv_obj_t * quick_function_create(lv_obj_t * tileview, uint16_t id)
{
    lv_obj_t * tab = launcher_tileview_add_tile(tileview, id);
    LV_ASSERT_MEM(tab);
    if(tab == NULL) return NULL;

    lv_obj_t * content = lv_cont_create(tab, NULL);
    LV_ASSERT_MEM(content);
    if(content == NULL) return NULL;
    lv_obj_add_style(content, LV_LABEL_PART_MAIN, &lv_watch_style_transp);
    lv_obj_set_size(content,  lv_obj_get_width(tab), lv_obj_get_height(tab));
    //lv_cont_set_layout(content, LV_LAYOUT_GRID);
    lv_cont_set_layout(content, LV_LAYOUT_OFF);
    lv_obj_set_click(content, false);

    lv_obj_t * btn;
    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, ICON_CLEAN_FAST);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, ICON_CLEAN_FAST);
    lv_obj_set_event_cb(btn, btn_event_cb);
    lv_obj_align(btn, tab, LV_ALIGN_IN_LEFT_MID, 40, 0);
    lv_tileview_add_element(tileview, btn);

    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, get_shutdown_src());
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, get_shutdown_src());
    if(watch_modem_sim_present_check_req()) {
        lv_obj_set_event_cb(btn, NULL);
    } else {
        lv_obj_set_event_cb(btn, shutdown_create_btn_action);
    }
    lv_obj_align(btn, tab, LV_ALIGN_IN_RIGHT_MID, -40, -40);
    lv_tileview_add_element(tileview, btn);

    btn = lv_imgbtn_create(content, NULL);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_RELEASED, ICON_QRCODE);
    lv_imgbtn_set_src(btn, LV_BTN_STATE_PRESSED, ICON_QRCODE);
    lv_obj_set_event_cb(btn, qrcode_create_event_cb);
    lv_obj_align(btn, tab, LV_ALIGN_IN_RIGHT_MID, -50, 40);
    lv_tileview_add_element(tileview, btn);

    return tab;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static void * get_shutdown_src(void)
{
    if(watch_modem_sim_present_check_req()) {
        return (void *)ICON_SHUTDOWN_FORBIDDEN;
    }

    return (void *)ICON_SHUTDOWN;
}

#endif /*USE_LV_WATCH_QUICK_FUNCTION*/
